Climate change#

Student names: Thierry Schneider, Mark Kuster, Thomas Andersen, Jens Breusers

Team number: N7

Hide code cell source
# kaas Load image from link
url = r"Climate-Change-Threat-or-Opportunity-@aura-emagazine.jpg"

# Display image from URL with smaller size and subtitle
from IPython.display import Image, display

# Set the desired image width and height
width = 600
height = 300

# Set the subtitle text
subtitle = "© Zakariya Khan"

# Create an Image instance with the URL
image = Image(url=url, width=width, height=height)

# Display the image and subtitle
display(image)
print(subtitle)
© Zakariya Khan

Introduction#

Climate change is one of the most talked about and biggest issues of our time, affecting global weather patterns, posing significant risks to ecosystems, economies, and communities. Central to understanding this phenomenon are two critical indicators: temperature changes and carbon dioxide (CO2) emissions. This data story aims to explore the intricate relationship between these two factors using comprehensive datasets on global temperature changes and CO2 emissions over time. By analyzing global temperature records and CO2 emission data, we can uncover trends and correlations that will show more information on the progression of climate change. This project will provide visualizations and insights into how rising CO2 levels are influencing global temperatures, highlighting the urgent need for effective climate action.

CO2 is Ruining the Environment by Increasing Temperature#

The scientific consensus is clear: rising levels of CO2 and other greenhouse gases in the atmosphere are driving global temperatures upward, leading to catastrophic environmental consequences. A line graph showing CO2 emissions per year for countries illustrates this trend. As CO2 emissions have increased, particularly in industrialized and rapidly developing nations, global temperatures have risen correspondingly.

The First Argument#

An interactive world map with a slider for every year from 1990 to 2019 demonstrates how temperature changes from the previous year correlate with these rising CO2 levels. This visualization highlights the reality that as CO2 emissions surged, global temperatures also escalated, triggering a cascade of environmental issues, including more frequent and severe weather events, melting polar ice caps, and rising sea levels.

# Install nbformat if not already installed

import pandas as pd
import plotly.express as px

# Load the dataset
file_path = "Environment_Temperature_change_E_All_Data_NOFLAG.csv"
df = pd.read_csv(file_path, sep=",", encoding='latin1', on_bad_lines='skip', low_memory=False)

# Filter and aggregate the data for temperature changes
temperature_df = df[df['Element'] == 'Temperature change']

# Select a subset of years (e.g., 2000 to 2019)
selected_years = [f"Y{year}" for year in range(1990, 2020)]

# Melt the dataframe to have selected years as a single column
temperature_melted = temperature_df.melt(
    id_vars=['Area'],
    value_vars=selected_years,
    var_name='Year',
    value_name='TemperatureChange'
)

# Clean up the year column
temperature_melted['Year'] = temperature_melted['Year'].str[1:]

# Determine the min and max temperature changes for consistent color scale
min_temp_change = temperature_melted['TemperatureChange'].min()
max_temp_change = temperature_melted['TemperatureChange'].max()

# Create a choropleth map using Plotly
fig = px.choropleth(
    temperature_melted,
    locations="Area",
    locationmode="country names",
    color="TemperatureChange",
    hover_name="Area",
    animation_frame="Year",
    color_continuous_scale=px.colors.sequential.Plasma,
    range_color=(min_temp_change, max_temp_change),
    title="Global Temperature Change (1990-2019)"
)

fig.update_layout(
    geo=dict(
        showframe=False,
        showcoastlines=False,
        projection_type='equirectangular'
    ),
    margin={"r":0,"t":0,"l":0,"b":0}
)

fig.show()

Figure 1: World heatmap

The Second Argument#

The filled area plot showing population growth per year underscores another critical point: as the global population increases, so does the demand for energy and resources, which often results in higher CO2 emissions. This further amplifies the environmental degradation, creating a vicious cycle. The evidence overwhelmingly supports the need for urgent action to reduce CO2 emissions to mitigate these devastating impacts on our environment and ensure a sustainable future.

import pandas as pd
import plotly.express as px

# Load the dataset
df = pd.read_csv(r"energy_CSV.csv", encoding='ISO-8859-1')

# Check the first few rows and columns of the dataframe to ensure it's loaded correctly
# print(df.head())
# print(df.columns)

# Assuming 'Year' is the column for years, 'Population' is the column for population, and 'Country' is the column for country in your dataset
year_column = 'Year'
population_column = 'Population'
country_column = 'Country'

# Select the countries you want to plot
countries_to_plot = ['Bosnia and Herzegovina', 'Netherlands', 'Brazil', 'Japan']  # Ensure these match the country names in your dataset

# Filter the data for the selected countries
df_filtered = df[df[country_column].isin(countries_to_plot)]

# Create the area plot
fig = px.area(df_filtered, x=year_column, y=population_column, color=country_column,
              title="Population growth over years",
              labels={year_column: "Year", population_column: "Population growth"})

# Update the layout to set the x-axis range
fig.update_layout(xaxis=dict(range=[1980, 2020]))

# Show the plot
fig.show()

Figure 2: Filled area plot

CO2 Emissions are Necessary to Keep the World Turning#

The First Argument#

While the environmental impact of CO2 emissions is undeniable, it is also important to recognize the role that these emissions play in sustaining modern society. A bubble graph showing energy consumption per population illustrates the dependence on fossil fuels for energy needs. Countries with higher energy consumption, have larger bubbles, indicating their significant CO2 emissions. This energy consumption is integral to economic growth, job creation, and the development of infrastructure.

import pandas as pd
import plotly.express as px

# Load your dataset
df = pd.read_csv(r"energy_CSV.csv", encoding='ISO-8859-1')

# # Check the first few rows and columns of the dataframe to ensure it's loaded correctly
# print(df.head())
# print(df.columns)

# Assuming your dataset columns are named accordingly:
# Replace these with actual column names from your dataset
country_column = 'Country'
gdp_column = 'GDP'
energy_column = 'Energy_consumption'
continent_column = 'Energy_type'  # Adjust to the actual column name in your dataset
population_column = 'Population'  # Adjust to the actual column name in your dataset
year_to_plot = 2018

# Filter the data for the year 2018
df_2018 = df[df['Year'] == year_to_plot]

# Filter out rows with NaN values in 'Population' and 'Energy_consumption' columns
df_2018 = df_2018.dropna(subset=[population_column, energy_column])

# Create the scatter plot for the year 2018 with logarithmic scales for both axes
fig = px.scatter(df_2018, x=population_column, y=energy_column, 
                 color=continent_column,  # Use the correct column name for continent
                 size=gdp_column,  # Use GDP column for bubble sizes
                 hover_name=country_column,
                 log_x=True,  # Log scale for x-axis (Population)
                 log_y=True,  # Log scale for y-axis (Energy Consumption)
                 size_max=60,  # Adjust bubble size max limit as needed
                 title=f'Energy Consumption vs Population ({year_to_plot})',
                 labels={population_column: 'Population', energy_column: 'Energy ', continent_column: 'Energy Consumption', gdp_column: 'GDP'}
                )

# Customize layout (optional)
fig.update_layout(
    xaxis=dict(title='Population (log scale)'),
    yaxis=dict(title='Energy Consumption (log scale)'),
    legend_title='Energy units'
)

# Show the plot
fig.show()

Figure 3: bubble graph

The Second Argument#

Industries such as manufacturing, transportation, and energy production rely heavily on fossil fuels, which are currently the most efficient and cost-effective sources of energy. For many developing countries, industrialization and the associated CO2 emissions are essential for lifting populations out of poverty, providing access to essential services, and improving living standards. The line graph showing CO2 emissions per year for a few countries also reflects this necessity. As these nations develop, their CO2 emissions increase, highlighting the trade-off between economic growth and environmental impact.

import pandas as pd
import plotly.express as px

# Load the dataset
try:
    df_CO2 = pd.read_csv(r"CO2 emission by countries.csv", encoding='ISO-8859-1')
except FileNotFoundError:
    print("The file path is incorrect or the file does not exist.")
    raise
except Exception as e:
    print(f"An error occurred: {e}")
    raise

# Check the first few rows and columns of the dataframe to ensure it's loaded correctly
# print(df_CO2.head())
# print(df_CO2.columns)

# Replace these with the actual column names in your dataset
country_column = 'Country'
year_column = 'Year'
emissions_column = 'CO2 emission (Tons)'

# Select the countries you want to plot
countries_to_plot = ['Bosnia and Herzegovina', 'Japan', 'Netherlands', 'Brazil']  # Ensure these match the country names in your dataset

# Filter the data for the selected countries
df_filtered = df_CO2[df_CO2[country_column].isin(countries_to_plot)]

# Create the line plot
fig = px.line(df_filtered, x=year_column, y=emissions_column, color=country_column, title="CO2 Emissions Over Years")
fig.update_layout(xaxis=dict(range=[1980, 2020]))
fig.show()

Figure 4: line graph

more ideas for more plots:

  • CO2 emission per country per year, interactive world map.

  • line graph showing CO2 emmission per year and average global temperature per year.

Reflection#

This data visualization assignment allowed us to delve into the complex interplay between CO2 emissions and temperature changes. Through the process, we gained a clearer understanding of the environmental and economic dimensions of CO2 emissions.

The exercise highlighted the challenges in presenting data that supports two seemingly opposing perspectives. It required careful consideration of how to present data objectively and effectively. Creating visualizations that are both informative and engaging was a key aspect of this assignment, emphasizing the importance of clarity and accuracy in data storytelling.

Additionally, this assignment reinforced the value of visual tools in communicating complex issues. It underscored the importance of balancing environmental concerns with economic realities, providing insights into the multifaceted nature of global energy consumption and its impacts. Overall, it was a valuable learning experience in data analysis and visualization.

References#

add later